package tliasmanagement.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tliasmanagement.anno.Log;
import tliasmanagement.pojo.Clazz;
import tliasmanagement.pojo.ClazzQueryParam;
import tliasmanagement.pojo.Result;
import tliasmanagement.service.ClazzService;

/**
 * 班级管理
 * */
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /**
     * 分页查询
     * @param clazzQueryParam 页码
     * */
    @GetMapping
    public Result page(ClazzQueryParam clazzQueryParam){
      return Result.success(clazzService.page(clazzQueryParam));
    };

    /**
     * 新增班级
     * */
    @Log
    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }

    /**
     * 根据id查询班级信息
     * @param id 班级id
     */
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id){
        return Result.success(clazzService.getDetailInfo(id));
    }

    /**
     * 修改班级信息
     * @param clazz 班级信息
     * */
    @Log
    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     * @param id 班级id
     * */
    @Log
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return Result.success();
    }

    /**
     * 查询所有班级
     * */
    @GetMapping("/list")
    public Result list(){
        return Result.success(clazzService.list());
    }
}
